package com.jinlejia.bbs.http.utils;

import android.content.Context;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfListMode;
import com.jinlejia.erp.bean.SaveCookieBean;
import com.jinlejia.erp.utils.DbUtil;

import java.util.Map;

/**
 * @author 王进 on 2019/3/22.
 */

public class DataFilter {
    public static boolean filter(Context context, Map<String, Object> map, YfListAdapter adapter) {
        boolean flag = false;
        int code;
        try {
            code = Integer.parseInt(map.get("code").toString());
        }catch (NumberFormatException ignore){
            return flag;
        }

        if (code == 200) {
            flag = true;
            if (adapter != null)
                adapter.removeAllFooters();
        } else if (code == 300) {
            //有未审核的移动申请
            flag = false;
        } else if (code == 303) {
            //没有更多
            flag = false;
            if (adapter != null) {
                adapter.removeAllFooters();
                if (adapter.getData().size() > 10)
                    adapter.addFooter("已经没有更多");
            }
        } else if (code == 501) {
            //没有数据
            if (adapter != null)
                adapter.changeMode(YfListMode.MODE_EMPTY);
        } else if (code == 700) {
            //没有权限
            if (adapter != null) {
                adapter.changeMode(YfListMode.MODE_ERROR);
            } else {
//                new NoPermissionDialog(context).show();
            }
        } else if (code == 800) {
            DbUtil.getDB(context).single().delete(SaveCookieBean.class);
        } else if (code == 204){
            flag = false;
        }
        return flag;
    }

    public static boolean filter(Context context, Map<String, Object> map) {
        return DataFilter.filter(context, map, null);
    }
}
